package com.pureut.storage.service.impl;

import com.pureut.storage.domain.order.domain.CustomerManagement;
import com.pureut.storage.dto.CustomerManagementMqDto;
import com.pureut.storage.mapper.CustomerManagementMapper;
import com.pureut.storage.service.CustomerManagementService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * 客户数据同步实现层
 */
@RequiredArgsConstructor
@Service
public class CustomerManagementServiceImpl implements CustomerManagementService {

    private final CustomerManagementMapper customerManagementMapper;
    /**
     * 新增
     * @param mq
     * @return
     */
    @Override
    public void insertCustomerManagement(CustomerManagementMqDto mq) {
        if (mq.getCustomerNum() != null) {
            CustomerManagement customerManagement = new CustomerManagement();
            BeanUtils.copyProperties(mq, customerManagement);
            customerManagement.setId(mq.getId());
            customerManagement.setTenantId(mq.getTenantId());
            customerManagementMapper.insert(customerManagement);
        }
    }

    /**
     * 修改
     * @param mq
     * @return
     */
    @Override
    public void updateCustomerManagement(CustomerManagementMqDto mq) {
        CustomerManagement customerManagement = customerManagementMapper.selectById(mq.getId());
        BeanUtils.copyProperties(mq,customerManagement);
        customerManagementMapper.updateById(customerManagement);
    }

    /**
     * 删除
     * @param mq
     * @return
     */
    @Override
    public void deleteCustomerManagement(CustomerManagementMqDto mq) {
        List<String> idList = Arrays.asList(mq.getIdStr().split(","));
        customerManagementMapper.deleteData(idList);
    }
}
